﻿using UnityEngine;
using UnityEngine.UI;

namespace Zero.Dialogue
{
    public class UI_DialoguePanel : MonoBehaviour
    {
        public Text characterNameText;
        public Text bodyText;


        /// <summary>
        /// 设置对话框文本
        /// </summary>
        /// <param name="characterName">角色名字</param>
        /// <param name="body">文本主体</param>
        public void SetDialogueText(string characterName, string body)
        {
            // 设置轮廓颜色
            var nameOutline = characterNameText.GetComponent<Outline>();
            if (nameOutline != null)
            {
                var outlineColor = Color.white;
                outlineColor.a = nameOutline.effectColor.a;
                nameOutline.effectColor = outlineColor;
            }

            if (string.IsNullOrEmpty(characterName))
                characterNameText.gameObject.SetActive(false);
            else
            {
                characterNameText.gameObject.SetActive(true);
                characterNameText.text = characterName;
            }

            bodyText.text = body;

            // 激活对话框面板
            gameObject.SetActive(true);
        }
    }
}